//
//  KcPhotoCollectionViewCell.swift
//  KcSwiftDemo
//
//  Created by 张杰 on 2017/8/23.
//  Copyright © 2017年 张杰. All rights reserved.
//

import UIKit
import Kingfisher

public class KcPhotoCollectionViewCell: UICollectionViewCell {
    public static func cellWithCollectionView(_ collectionView: UICollectionView, indexPath: IndexPath) -> KcPhotoCollectionViewCell {
        let ID = "KcPhotoCollectionViewCell"
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath)
        return cell as! KcPhotoCollectionViewCell
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.addSubview(icon)
    }
    
    /// 默认为网络图片
    public func setIcon(_ imageName: String, isNetWork: Bool = true) {
        if isNetWork {
            icon.kf.setImage(with: URL(string: imageName))
        }
        else {
            icon.image = UIImage(named: imageName)
        }
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override public func layoutSubviews() {
        super.layoutSubviews()
        
        icon.frame = contentView.bounds
    }
    
    public lazy var icon: UIImageView = {
        let icon = UIImageView()
        icon.contentMode = .scaleAspectFit
        icon.clipsToBounds = true
        return icon
    }()
}
